Be sure to include OUT_DIR for doc tests
authorAlex Crichton <alex@alexcrichton.com>
Mon, 17 Nov 2014 18:34:27 +0000 (10:34 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 18 Nov 2014 22:15:24 +0000 (14:15 -0800)
src/cargo/ops/cargo_rustc/mod.rs
tests/test_cargo_compile_custom_build.rs

index 2032f6ec54507fa80fe55d7f57f3756b6d0d2698..21dbcd8288099221cc3646963623949c01152bf1 100644 (file)
@@ -148,6 +148,8 @@ pub fn compile_targets<'a>(env: &str, targets: &[&'a Target], pkg: &'a Package,
     // Now that we've figured out everything that we're going to do, do it!
     try!(queue.execute(cx.config));
 
+    let out_dir = cx.layout(pkg, KindTarget).build_out(pkg).display().to_string();
+    cx.compilation.extra_env.insert("OUT_DIR".to_string(), Some(out_dir));
     Ok(cx.compilation)
 }
 
index f373c7440b64de5974441335dc34b728e52e46df..735bbb84bc879c179167d13f4743abc9c1de6f42 100644 (file)
@@ -939,3 +939,37 @@ test!(transitive_dep_host {
     assert_that(p.cargo_process("build"),
                 execs().with_status(0));
 })
+
+test!(test_a_lib_with_a_build_command {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.5.0"
+            authors = []
+            build = "build.rs"
+        "#)
+        .file("src/lib.rs", r#"
+            include!(concat!(env!("OUT_DIR"), "/foo.rs"))
+
+            /// ```
+            /// foo::bar();
+            /// ```
+            pub fn bar() {
+                assert_eq!(foo(), 1);
+            }
+        "#)
+        .file("build.rs", r#"
+            use std::os;
+            use std::io::File;
+
+            fn main() {
+                let out = Path::new(os::getenv("OUT_DIR").unwrap());
+                File::create(&out.join("foo.rs")).write_str("
+                    fn foo() -> int { 1 }
+                ").unwrap();
+            }
+        "#);
+    assert_that(p.cargo_process("test"),
+                execs().with_status(0));
+})